<template>
<view>
<view class="head_bg">
  <image mode="widthFix" style="width: 100%" src="http://image1.sansancloud.com/xiaogu/2020_12/15/18/32/1_785.jpg"></image>  
</view>
<view class="container" v-if="productData!=null" style="top:198rpx;overflow:hidden">
<!-- <view class="productDetailSwiperContainer">
    <banner-component v-if="bannerData&&showBannerState" @bannerCurIndexFun="returnBannerDataFun" :receiveData="bannerData"></banner-component>
    <view class="swiperItemIndex">{{swiperIndex}}/{{totalImg}}</view>
  </view> -->
  <view class="product_info_block">
      <text class="product_name">{{productData.name}}</text>
      <text class="product_description">{{productData.description}}</text>
      <view class="product_tip_block">
          <image class="product_tip_icon" src="https://image1.sansancloud.com/xiaogu/2020_12/16/14/44/1_335.jpg?x-oss-process=style/preview_120"></image>
          <text class="product_tip_text">
              套餐起订量为一周，默认为包含周末早餐，如周末不需要用餐，可在周末早餐处取消“口”里的“√”
          </text>
      </view>
  </view>
<!--商品特卖  -->
  <view class="special_sale_list" v-if="productData.productInfo.itemSpecialSaleType||saleStrategyState">
    <text class="special_sale_title">促销</text>
    <view class="special_sale_data">
      <view class="special_sale_item" v-if="productData.productInfo.needJifen>0">
          <!--  v-if="productData.productInfo.needJifen>0" -->
        <view class="special_sale_item_type" :style="'border:1rpx solid ' + setting.platformSetting.defaultColor + ';color:' + setting.platformSetting.defaultColor">
          积分
        </view>
        <view class="special_sale_item_value">
          该产品需消耗
          <text :style="'color:' + setting.platformSetting.defaultColor+';font-weight: bold;'">
              {{productData.productInfo.needJifen||1000}}
          </text>
          积分
        </view>
      </view>
      <view class="special_sale_item" v-if="saleStrategyState">
        <view class="special_sale_item_type" :style="'border:1rpx solid ' + setting.platformSetting.defaultColor + ';color:' + setting.platformSetting.defaultColor">
          优惠
        </view>
        <view class="special_sale_item_value">
          {{productData.productInfo.saleStrategyName}}
        </view>
      </view>
      <view class="special_sale_item" v-if="productData.productInfo.itemSpecialSaleType">
        <view class="special_sale_item_type" :style="'border:1rpx solid ' + setting.platformSetting.defaultColor + ';color:' + setting.platformSetting.defaultColor">
          <text v-if="productData.productInfo.itemSpecialSaleType==1">满减</text>
          <text v-if="productData.productInfo.itemSpecialSaleType==2">买赠</text>
          <text v-if="productData.productInfo.itemSpecialSaleType==3">限购</text>
          <text v-if="productData.productInfo.itemSpecialSaleType==4">日限购</text>
          <text v-if="productData.productInfo.itemSpecialSaleType==5">周限购</text>
          <text v-if="productData.productInfo.itemSpecialSaleType==6">月限购</text>
          <text v-if="productData.productInfo.itemSpecialSaleType==7">活动限购</text>
          <text v-if="productData.productInfo.itemSpecialSaleType==8">会员特卖</text>
        </view>
        <view class="special_sale_item_value">
          <view v-if="productData.productInfo.itemSpecialSaleType==1">满
            <text :style="'color:' + setting.platformSetting.defaultColor+';font-weight: bold;'">
                ￥{{productData.productInfo.itemSpecialSaleValue1}}
            </text>减
            <text :style="'color:' + setting.platformSetting.defaultColor+';font-weight: bold;'">
                ￥{{productData.productInfo.itemSpecialSaleValue2}}
            </text>
          </view>
          <view v-if="productData.productInfo.itemSpecialSaleType==2">买
              <text :style="'color:' + setting.platformSetting.defaultColor+';font-weight: bold;'">
                  {{productData.productInfo.itemSpecialSaleValue1}}
              </text>件,赠
              <text :style="'color:' + setting.platformSetting.defaultColor+';font-weight: bold;'">
                  {{productData.productInfo.itemSpecialSaleValue2}}
              </text>件
          </view>
          <view v-if="productData.productInfo.itemSpecialSaleType==3||productData.productInfo.itemSpecialSaleType==4||productData.productInfo.itemSpecialSaleType==5||productData.productInfo.itemSpecialSaleType==6||productData.productInfo.itemSpecialSaleType==7">
              限购<text :style="'color:' + setting.platformSetting.defaultColor+';font-weight: bold;'">
                  {{productData.productInfo.itemSpecialSaleValue1}}
              </text>件
          </view>
          <view v-if="productData.productInfo.itemSpecialSaleType==4">日限购{{productData.productInfo.itemSpecialSaleValue1}}件</view>
          <view v-if="productData.productInfo.itemSpecialSaleType==5">限购{{productData.productInfo.itemSpecialSaleValue1}}件</view>
          <view v-if="productData.productInfo.itemSpecialSaleType==6">限购{{productData.productInfo.itemSpecialSaleValue1}}件</view>
          <view v-if="productData.productInfo.itemSpecialSaleType==7">限购{{productData.productInfo.itemSpecialSaleValue1}}件</view>
          <view v-if="productData.productInfo.itemSpecialSaleType==8">会员特卖</view>
        </view>
      </view>
    </view>
  </view>
  <view class="product_package_list_block">
      <checkbox-group @change="checkboxChange">
      <view class="product_package_item" v-for="(item,index) in packageList" :key="index">
          <view class="product_package_item_title">
              <view style="display: flex;">
                  <text class="product_package_item_title_icon"></text>
                  <text class="product_package_item_title_text">{{item.name}}</text>
              </view>
              <label class="itemCheckbox" v-if="item.enable==1">
                <checkbox :checked="true" :color="setting.platformSetting.defaultColor" :value="index"></checkbox>
              </label> 
          </view>
          <scroll-view class="product_package_product_list" scroll-x="true" v-if="item.products.length!=0">
              <view class="product_package_product_item" v-for="(itemTwo,indexTwo) in item.products" :key="indexTwo">
                  <image class="product_package_product_item_img" :src="itemTwo.icon"></image>
                  <text class="product_package_product_item_name">{{itemTwo.name}}</text>
                  <view class="change_product_btn" @tap='showPintuan(itemTwo.allReplaceStore,index,indexTwo)' v-if="itemTwo.allReplaceStore&&itemTwo.allReplaceStore.length!=0">换</view>
                  <view class="change_product_btn" style="background: #888;" v-else>不可换</view>
                  
                  <text class="jia" v-if="indexTwo<item.products.length-1">+</text>
              </view>
              <!-- <text class="jia">+</text> -->
          </scroll-view>
          <text v-else style="padding: 30rpx;">暂无产品</text>
      </view>
      </checkbox-group>
  </view>
    <view class="product_introduce">
      <view class="product_introduce_short" v-if="attrsState">
        <text class="product_introduce_title">商品介绍</text>
        <view class="product_introduce_item" v-for="(item, index) in productData.attrs" :key="index">
            <text class="product_introduce_item_name">{{item.attributeName}}</text>
            <text class="product_introduce_item_vaule">{{item.attributeValue}}</text>
        </view>
      </view>
    </view>
    <!-- 首页组件-私有产品详情装饰-->
    <view style="margin-top:20rpx;">
     <custom-page-index-component :receiveData="sendProductData" v-if="sendProductData"></custom-page-index-component>
    </view>
    <!-- 富文本 -->
    <!-- <view class="product_main_info" v-if="productData.description.description!=''&&productData.description.description!='<p><br></p>'">
      <text>图文详情</text>
    </view>
    <view class="tab_detail_container" v-if="productData.description.description!=''&&productData.description.description!='<p><br></p>'">
       <view class="wxParseHtmlContainer"> 
		  <rich-text-component :receiveData="articleJsonData" v-if="articleJsonData"></rich-text-component>
	   </view>
    </view> -->

 <!-- 首页组件-公共产品详情装饰-->
 <custom-page-index-component :receiveData="sendIndexData" v-if="sendIndexData"></custom-page-index-component>
</view>


<!-- 底部按钮们 -->
<view class="bottomHeight"></view>
<view class="product_detail_bottom_container">
    <text class="product_price">￥{{allPrice}}</text>
    <view class='item_infomation_nums'>
      <image style='border-top-left-radius: 0.2em;border-bottom-left-radius: 0.2em;' 
        src='https://image1.sansancloud.com/xianhua/2019_12/17/21/40/33_565.jpg?x-oss-process=style/preview_120' :class="(allCount == 1 ?'noadd':'')"  @tap='subNum'></image>
      <text class='flexCenter'>{{allCount}}周</text>
      <image style='border-top-right-radius: 0.2em; border-bottom-right-radius: 0.2em;'  src='https://image1.sansancloud.com/xianhua/2019_12/17/21/40/33_660.jpg?x-oss-process=style/preview_120' @tap='addNum' ></image>
    </view>
    <view class="place_the_order" data-way="buy" @tap="confirmReserve">下单</view>
</view>

<posters-component :proId="proId" :shopId="shopId" :ewmImgUrl="qrCodeUrl" v-if="posterState" @closePoaster="getChilrenPoster"></posters-component> 
<pintuan-component :pintuanParam="replaceStoreData" v-if="pintuanPopupState&&replaceStoreData" @closePintuan="getChilrenPintuan" @goPintuan="replaceStoreDataFun"></pintuan-component>
<measure-card-component v-if='showCount' :showCount="showCount" :pintuanParams="pintuanParams" :productData='productData' :byNowParams="byNowParams" :bindway="bindway" @closeCard="getCloseCardFun"></measure-card-component>
<view class="select_share_list" :animation="animationDataTwo">
  <view class="select_share_item" v-for="(item, index) in shareTypeData" :key="index">
    <text class="select_share_name" @click.stop="showPoster" v-if="item.type=='text'">{{item.name}}</text>
    <button open-type="share" class="select_share_name" v-else>{{item.name}}</button>
  </view>
  <view class="select_share_item cancel_select_share" @tap="closeZhezhao">
    <text class="select_share_name">取消</text>
  </view>
</view>
<view class='zhezhao' v-if="showTypeTwo" @tap='closeZhezhao'></view>
</view>
</template>

<script>

import publicFun from '../../wxcomponents/public/publicFun.wxs'
var WxParse = require('../../wxcomponents/wxParse/wxParse.js')

export default {
  data() {
    return {
      setting: null,
      // setting 
      productData: null,
      levelZero:0,
      saveMoney:0,
      shareMoney:"0",
      // 商品数据 
      cart: null,
      countGood: 0,
      sysWidth: 320,
      //图片大小
      showCount: false,
      saleStrategyState: false,
      measuresState: false,
      positionState: false,
      attrsState: false,
      targs: [],
      posterState: false,
      showTypeTwo: false,
      pintuanPopupState: false,
      proId: '',
      shopId: '',
      bindway: 'cart',
      //点击的是加入购物车或者立即购买
      showState: 0,
      commitList: [],
      measurementJson: null,
      qrCodeUrl: "",
      haveMeasuresState: false,
      selectTypeData: null,
      swiperIndex: 1,
      totalImg: 0,
      pintuanId: 0,
      pintuanState: false,
      promotionState: false,
      pintuanListData: [],
      color: '',
      secondColor: "",
      clientNo: '',
      minCount: '1',
      sendIndexData: {},
      buyType: 'normal',
      scanExhauseList: [],
      byNowParams: {
        productId: '',
        itemCount: 1,
        shopId: '',
        cartesianId: '0',
        fromSource: 'mini',
        orderType: ''
      },
      pintuanParams: {
        pintuanCreateType: 0,
        pintuanRecordId: 0
      },
      dataFOr_getData: {
        id: '',
        addShopId: ''
      },
      pintuanParam: "",
      visiblePintuanNum: 0,
      sendProductData: "",
      showGuigeType: false,
      article: "",
	  articleJsonData:'',
	  MeasureParams:[],
      showBannerState:true,
      clearTimeState:false,
      bannerData:null,
      animationDataTwo: null,
      shareTypeData: [{
        name: '发送给朋友',
        type: 'botton'
      }, {
        name: '生成海报',
        type: 'text'
      }],
      userLevelList:[],
      loginUser:null,
      replaceStoreData:null,
      // showPerFormState:false,
      // animationData:null,
      // sendOptionData:null,
      // packageList:[
      //     {id:1,name:'周一早餐',productList:[{name:'精磨玉米汁',icon:'http://image1.sansancloud.com/xiaogu/2020_12/16/15/16/11_62.jpg'},{name:'鲜肉包',icon:'http://image1.sansancloud.com/xiaogu/2020_12/16/15/16/11_184.jpg'}],},
      //     {id:2,name:'周二早餐',productList:[{name:'精磨玉米汁',icon:'http://image1.sansancloud.com/xiaogu/2020_12/16/15/16/11_62.jpg'},{name:'鲜肉包',icon:'http://image1.sansancloud.com/xiaogu/2020_12/16/15/16/11_184.jpg'}],},
      //     {id:3,name:'周三早餐',productList:[{name:'精磨玉米汁',icon:'http://image1.sansancloud.com/xiaogu/2020_12/16/15/16/11_62.jpg'},{name:'鲜肉包',icon:'http://image1.sansancloud.com/xiaogu/2020_12/16/15/16/11_184.jpg'}],},
      //     {id:4,name:'周四早餐',productList:[{name:'精磨玉米汁',icon:'http://image1.sansancloud.com/xiaogu/2020_12/16/15/16/11_62.jpg'},{name:'鲜肉包',icon:'http://image1.sansancloud.com/xiaogu/2020_12/16/15/16/11_184.jpg'}],},
      //     {id:5,name:'周五早餐',productList:[{name:'精磨玉米汁',icon:'http://image1.sansancloud.com/xiaogu/2020_12/16/15/16/11_62.jpg'},{name:'鲜肉包',icon:'http://image1.sansancloud.com/xiaogu/2020_12/16/15/16/11_184.jpg'}],},
      //     {id:6,type:'select',name:'周六早餐',productList:[{name:'精磨玉米汁',icon:'http://image1.sansancloud.com/xiaogu/2020_12/16/15/16/11_62.jpg'},{name:'鲜肉包',icon:'http://image1.sansancloud.com/xiaogu/2020_12/16/15/16/11_184.jpg'}],},
      //     {id:7,type:'select',name:'周日早餐',productList:[{name:'精磨玉米汁',icon:'http://image1.sansancloud.com/xiaogu/2020_12/16/15/16/11_62.jpg'},{name:'鲜肉包',icon:'http://image1.sansancloud.com/xiaogu/2020_12/16/15/16/11_184.jpg'}],},
      // ],
      packageList:[
        {name:'周一套餐',paramName:'monday',products:[],replaceStore:[],enable:0},
        {name:'周二套餐',paramName:'tuesday',products:[],replaceStore:[],enable:0},
        {name:'周三套餐',paramName:'wednesday',products:[],replaceStore:[],enable:0},
        {name:'周四套餐',paramName:'thursday',products:[],replaceStore:[],enable:0},
        {name:'周五套餐',paramName:'friday',products:[],replaceStore:[],enable:0},
        {name:'周六套餐',paramName:'saturday',products:[],replaceStore:[],enable:1},
        {name:'周日套餐',paramName:'sunday',products:[],replaceStore:[],enable:1},
      ],
      checkedList:[5,6],
      allPrice:0,
      weekPrice:0,
      allCount:1,
    };
  },
  props: {},
  onError: function (options) {
    console.log("on error!!!");
  },
  onLoad: function (options) {
    this.publicFun = publicFun;
    console.log('--------product----------', options);
    let that = this;
    that.setData({
      showBannerState:true,
      sysWidth: getApp().globalData.sysWidth,
      proId: options.id || options.productId,
      shopId: options.addShopId||236,
      clientNo: getApp().globalData.clientNo,
      color: getApp().globalData.setting.platformSetting.defaultColor,
      secondColor: getApp().globalData.setting.platformSetting.secondColor,
      levelZero:getApp().globalData.setting.platformSetting.levelZero
    });
    let sendIndexData = JSON.stringify({
      title: 'noTitle',
      url: "productdetail",
      params: {
        pageObjectId: options.id || options.productId
      }
    });
    that.setData({
      sendIndexData: sendIndexData
    });
    let sendProductData = JSON.stringify({
      title: 'noTitle',
      url: "product_detail_" + (options.id || options.productId)
    });
    that.setData({
      sendProductData: sendProductData
    });
    console.log("商品id和店铺id", options);
    that.dataFOr_getData.id = options.id || options.productId;
    that.dataFOr_getData.addShopId = options.addShopId;
    that.setData({
      dataFOr_getData: that.dataFOr_getData
    });
    that.optionsData = options;
    that.getData(that.optionsData);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    let loginUser=getApp().globalData.loginUser||null;
    let that=this;
    if (loginUser) {
      that.setData({
        loginUser: loginUser
      });
    } else {
      getApp().globalData.addLoginListener(that);
    }
    that.setData({
      setting: getApp().globalData.setting,
      userLevelList:getApp().globalData.setting.platformSetting.userLevels||[],
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      let that=this;
      that.setData({
        showBannerState:true,
      })
      if(that.clearTimeState){
        that.setData({clearTimeState:false})
      }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
      this.setData({
        showBannerState:false,
      })
      this.setData({clearTimeState:true})
      console.log("==this.$refs===",this.$refs)
      // this.$refs.productTimeOne?this.$refs.productTimeOne.setShowTimeStateFun(true):'';
      // this.$refs.productTimeTwo?this.$refs.productTimeTwo.setShowTimeStateFun(true):'';
      // this.$refs.productTimeThree?this.$refs.productTimeThree.setShowTimeStateFun(true):'';
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
      this.setData({
        showBannerState:false,
      })
      console.log("==this.$refs===",this.$refs)
      this.setData({clearTimeState:true})
      // this.$refs.productTimeOne?this.$refs.productTimeOne.setShowTimeStateFun(true):'';
      // this.$refs.productTimeTwo?this.$refs.productTimeTwo.setShowTimeStateFun(true):'';
      // this.$refs.productTimeThree?this.$refs.productTimeThree.setShowTimeStateFun(true):'';
    },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareTimeline:function(){
      return this.shareFun()
  },
  onShareAppMessage: function (res) {
    console.log(res);
    return this.shareFun()
  },
  methods: {
    subNum: function () {
      let that=this;
      if (that.allCount==1) {
        return
      }
      that.allCount--;
      that.allPrice=(that.weekPrice*that.allCount).toFixed(2)
    },
    addNum: function () {
      this.allCount++;
      this.allPrice=(this.weekPrice*this.allCount).toFixed(2)
    },
    replaceStoreDataFun:function(data){
        console.log("==replaceStoreDataFun===",data);
        let that=this;
        that.pintuanPopupState=false;
        let index=data.detail.data.index;
        let indexTwo=data.detail.data.indexTwo;
        let itemData=data.detail.data.item;
        console.log("==itemData===",index,indexTwo,itemData)
        let products=that.packageList[index].products;
        console.log("==products===",products)
        let newProduct=products[indexTwo];
        that.$set(newProduct,'name',itemData.name)
        that.$set(newProduct,'icon',itemData.icon)
        that.$set(newProduct,'productId',itemData.productId)
        that.$set(newProduct,'price',itemData.price)
        let newProducts=products.splice(indexTwo,1,newProduct)
        // that.$set(that.packageList[index],'products',newProducts)
    },
    /* 确认预定场馆 */
    confirmReserve:function(){
      let that=this;
      console.log("=====confirmReserve========",that.checkedList)
      let subscribeBag={price:that.productData.price||0,count:that.allCount};
      for(let i=0;i<that.packageList.length;i++){
          if(that.packageList[i].enable==0){
              let paramName=that.packageList[i].paramName;
              that.$set(subscribeBag,paramName,that.packageList[i])
          }else{
            if(that.checkedList){
                for(let j=0;j<that.checkedList.length;j++){
                    let paramName=that.packageList[that.checkedList[j]].paramName;
                    that.$set(subscribeBag,paramName,that.packageList[that.checkedList[j]])
                }
                
            }  
          }
      }
      console.log('====subscribeBag===',subscribeBag)
      let userId=0
      if (getApp().globalData.loginUser && getApp().globalData.loginUser.platformUser) {
        userId ='MINI_PLATFORM_USER_ID_' + getApp().globalData.loginUser.platformUser.id;
      } // console.log("app.loginUser.platformUser", app.loginUser.platformUser.id)
      let params = { bagId: that.proId,subscribeBag:JSON.stringify(subscribeBag),userId:userId};
      var customIndex = getApp().globalData.AddClientUrl('/wx_create_week_subscribe_bag_order.html', params, 'post')
      getApp().globalData.showToastLoading('loading', true)
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log("=====confirmReserve_res======", res.data)
          if (res.data.errcode == 0) {
            wx.navigateTo({
              url: '/pages/edit_order/index?orderNo=' + res.data.relateObj.orderNo,
            })
          }
          wx.hideLoading()
        },
        fail: function (res) {
          console.log("fail")
          wx.hideLoading()
          getApp().globalData.loadFail()
        },
        complete: function () {
         
        },
      })
    },
    checkboxChange: function (e) {
      console.log('--------checkBox------');
      console.log(e.detail.value, 'value+++',this.checkedList);
      var checkedItem = e.detail.value;
      this.checkedList= e.detail.value;
      if(checkedItem.length!=0){
          this.weekPrice=(this.productData.price*(5+checkedItem.length)).toFixed(2)
          this.allPrice=(this.productData.price*(5+checkedItem.length)*this.allCount).toFixed(2)
      }else{
          this.weekPrice=(this.productData.price*5).toFixed(2)
          this.allPrice=(this.productData.price*5*this.allCount).toFixed(2)
      }
    },
    shareFun:function(){
        let that = this;
        let params = that.dataFOr_getData;
        let productItem = that.productData.productInfo;
        
        if (!productItem.brandName || productItem.brandName == "") {
          productItem.brandName = "";
        };
        let shareName = '活动价：￥' + productItem.price + '(原价：￥' + productItem.tagPrice + ')' + productItem.brandName + productItem.name;
        console.log('params:', params, that.productData);
        return getApp().globalData.shareForFx2('productDetail', shareName, params,productItem.imagePath||'');
    },
    showShareBlock: function () {
      this.setData({
        showTypeTwo: !this.showTypeTwo
      });
      let showTypeTwo = this.showTypeTwo;
      let animation = wx.createAnimation({
        duration: 400,
        timingFunction: 'ease-in-out'
      });
      console.log("=======popupFormPage==========", animation, this.showType);

      if (showTypeTwo) {
        animation.height(150).step();
      } else {
        animation.height(0).step();
      }

      this.setData({
        animationDataTwo: animation.export()
      });
    },
    tolinkUrl: function (data) {
      let that = this;
      console.log("data", data);
      let linkUrl = data.currentTarget ? data.currentTarget.dataset.link : data;
      console.log("==linkUrl===", linkUrl);
      getApp().globalData.linkEvent(linkUrl);
    },
    getCloseCardFun:function(data){
        let that=this;
        console.log("===getCloseCardFun==",data)
        that.setData({showCount:false})
    },
    /*轮播图下标*/
    swiperChange: function (e) {
      this.setData({
        swiperIndex: e.detail.current + 1
      });
    },
    returnBannerDataFun:function(e){
      let that=this;
      this.setData({
        swiperIndex: e.detail.index + 1
      });
    },
    getChilrenPintuan(e) {
      let that = this;
      that.setData({
        pintuanPopupState: false
      });
    },

    showPintuan: function (data,index,indexTwo) {
      console.log('====showPintuan===',data);
      let that = this;
      that.setData({
        replaceStoreData:{data:data,index:index,indexTwo:indexTwo},
        pintuanPopupState: true
      });
    },
    showPoster: function () {
      console.log('===showPoster====', getApp().globalData.clientNo);
      let that = this;
      that.getQrCode();
      that.setData({
        posterState: true
      });
    },
    toIndex: function () {
      getApp().globalData.toIndex();
    },
    posterStateFun: function (state) {
      console.log('====state====', state);
      this.setData({
        posterState: true
      });
    },
    getChilrenPoster: function (e) {
      console.log('=======', e);
      this.setData({
        posterState: false
      });
    },
    lookBigImage: function (e) {
      console.log("111111111", e.currentTarget.dataset);
      let imgSrc = e.currentTarget.dataset.imageurl;
      let imgArray = [];
      let index = e.currentTarget.dataset.index;
      let PostImageSrc = [];
      console.log(imgSrc);

      for (let i = 0; i < imgSrc.length; i++) {
        imgArray.push(imgSrc[i].imagePath);
        PostImageSrc.push(imgSrc[i].imagePath.replace(/http/, "https"));
      } 
      console.log(PostImageSrc);
      if (!imgSrc) {
        return;
      }
      wx.previewImage({
        current: imgArray[index],
        // 当前显示图片的http链接
        urls: imgArray // 需要预览的图片http链接列表

      });
    },
    showCouponState: function (e) {
      var index = e.currentTarget.dataset.id;
      this.setData({
        showState: index
      });
    },
    aaaaa: function (e) {
      console.log("hello");
      getApp().globalData.linkEvent("product_detail_9218.html");
    },

    /* 删除收藏 */
    removeFavourite: function (e) {
      var that = this;
      getApp().globalData.showToastLoading('loading', true);
      var postData = {
        itemId: '',
        favoriteType: '1'
      };
      let productData = this.productData;
      postData.itemId = e.currentTarget.dataset.itemid;
      var customIndex = getApp().globalData.AddClientUrl("/remove_favorite.html", postData, 'post');
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log(res.data);

          if (res.data.errcode == '0') {
            productData.productInfo.favorite = 0;
            that.setData({
              productData: productData
            });
            console.log('000---' + that.productData.productInfo.favorite);
          }
        },
        fail: function (res) {
          getApp().globalData.loadFail();
        },
        complete: function (res) {
          wx.hideLoading();
        }
      });
    },

    /* 加入收藏 */
    addToFavourite: function (e) {
      var that = this;
      var postData = {
        itemId: '',
        favoriteType: '1'
      }; 
      getApp().globalData.showToastLoading('loading', true);
      let productData = this.productData;
      postData.itemId = e.currentTarget.dataset.itemid;
      console.log(postData);
      var customIndex = getApp().globalData.AddClientUrl("/add_to_favorite.html", postData, 'post');
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log(res.data);

          if (res.data.errcode == '0') {
            productData.productInfo.favorite = 1;
            that.setData({
              productData: productData
            });
            console.log('111---' + that.productData.productInfo.favorite);
          }
        },
        fail: function (res) {
          getApp().globalData.loadFail();
        },
        complete: function (res) {
          wx.hideLoading();
        }
      });
    },

    /* 查看图文详情   -- 已禁用 */
    lookDerection: function (e) {
      var images = e.currentTarget.dataset.derection;
      var sentMessage = "";

      for (let i = 0; i < images.length; i++) {
        sentMessage += "&" + i + "=" + images[i];
      }

      sentMessage = sentMessage.substring(1);
      console.log(sentMessage);
      wx.navigateTo({
        url: '/pages/productDetail_derection/index?' + sentMessage
      });
    },
    ChangeParam: function (params) {
      var returnParam = "";

      for (let i in params) {
        returnParam += "&" + i + "=" + params[i];
      }

      return returnParam;
    },

    /* dadianhua */
    callShop: function () {
      if (this.setting) {
        wx.makePhoneCall({
          phoneNumber: this.setting.platformSetting.defaultShopBean.telno //仅为示例，并非真实的电话号码

        });
      }
    },
    toCart: function () {
      console.warn("cart"); // let url ="shopping_car_list_new.html"
      getApp().globalData.linkEvent("shopping_car_list_new.html");
    },

    /* 找到购物车里面的内容 */
    findInCart: function (data) {
      var cart = null;
      this.postParams(data);
    },
    // readyPay: function (e) {
    //   this.setData({
    //     showCount: true
    //   });
    //   let info = e.currentTarget.dataset.item;
    //   this.byNowParams.productId = info.productId;
    //   this.byNowParams.shopId = info.belongShopId;
    //   this.byNowParams.orderType = 0;
    //   this.setData({
    //     byNowParams: this.byNowParams
    //   });
    // },
    readyPay2: function (e) {
      console.log('====e=====', e);
      // if (!getApp().globalData.checkIfLogin()) {
      //   return;
      // }
      if(!getApp().globalData.loginUser){
          let url="productDetail.html?id="+this.proId;
          let backUrl=encodeURIComponent(url)
          getApp().globalData.checkIfLogin(backUrl);
          return
      }
      if (this.productData.productInfo.promotionBean && this.productData.productInfo.promotionBean.promotionStatus == 2) {
        console.log('活动已结束！');
        wx.showToast({
          title: '活动已结束！',
          image: '/wxcomponents/images/icons/tip.png',
          duration: 1000
        });
        return;
      }

      let productData = this.productData;
      let way;
      let pintuanRecordId;
      console.log(productData);

      if (e.currentTarget.dataset.way) {
        way = e.currentTarget.dataset.way;
        pintuanRecordId = e.currentTarget.dataset.pintuanid;
      } else {
        way = e.detail.data.way;
        pintuanRecordId = e.detail.data.pintuanid;
      }

      this.setData({
        bindway: way
      });
      console.log('====q=====', this.bindway);
      let info = productData.productInfo;
      this.byNowParams.productId = info.productId;
      this.byNowParams.shopId = info.belongShopId;
      this.setData({
        byNowParams: this.byNowParams
      });

      if (way == 'cart') {
        if (productData.measures.length == 0) {
          this.addtocart();
        } else {
          this.setData({
            showCount: true
          });
          this.byNowParams.orderType = 0;
          this.setData({
            byNowParams: this.byNowParams
          });
          // this.chooseMeasureItem();
        }
      } else if (way == 'pintuanOne') {
        //单独购买
        this.setData({
          showCount: true
        });
        this.byNowParams.orderType = 0;
        this.pintuanParams.pintuanCreateType = 0;
        this.pintuanParams.pintuanRecordId = 0;
        this.setData({
          byNowParams: this.byNowParams,
          pintuanParams: this.pintuanParams
        });
        // this.chooseMeasureItem();
      } else if (way == 'pintuanMore') {
        //参加拼团
        this.setData({
          showCount: true
        });
        this.byNowParams.orderType = 0;
        this.pintuanParams.pintuanCreateType = 1;
        this.pintuanParams.pintuanRecordId = 0;
        this.setData({
          byNowParams: this.byNowParams,
          pintuanParams: this.pintuanParams
        });
        // this.chooseMeasureItem();
      } else if (way == 'addPintuan') {
        //发起拼单
        this.setData({
          showCount: true
        });
        this.setData({
          pintuanPopupState: false
        });
        this.byNowParams.orderType = 0;
        this.pintuanParams.pintuanCreateType = 2;
        this.pintuanParams.pintuanRecordId = pintuanRecordId;
        this.setData({
          byNowParams: this.byNowParams,
          pintuanParams: this.pintuanParams
        });
        // this.chooseMeasureItem();
      } else if (way == 'select') {
        this.setData({
          showCount: true
        });
        this.byNowParams.orderType = 0;
        this.setData({
          byNowParams: this.byNowParams
        });
        // this.chooseMeasureItem();
      } else {
        this.setData({
          showCount: true
        });
        this.byNowParams.orderType = 0;
        this.setData({
          byNowParams: this.byNowParams
        });
        // this.chooseMeasureItem();
      }
    },
    closeZhezhao: function () {
      this.setData({
        showCount: false,
        showTypeTwo:false
      });
      let animation = wx.createAnimation({
        duration: 400,
        timingFunction: 'ease-out'
      });
      animation.height(0).step();
      let setData = animation.export();
      this.setData({
        animationDataTwo: setData
      });
    },

    /* 创建订单 */
    createOrder22: function (o) {
      console.log('========createOrder22======', o);
      let that = this;
      let productInfo = that.productData.productInfo;
      let params = Object.assign({}, params, that.byNowParams, that.pintuanParams);
      console.log("=======", that.byNowParams, that.pintuanParams);
      getApp().globalData.showToastLoading('loading', true);
      getApp().globalData.createOrder(that.byNowParams, that.pintuanParams);
    },

    /* 加入購物車 */
    addtocart: function () {
      if (!getApp().globalData.checkIfLogin()) {
        return;
      }
      var params = {
        cartesianId: '',
        productId: '',
        shopId: '',
        count: '',
        type: ''
      };

      if (this.productData.measures.length == 0) {
        params.cartesianId = '0';
      } else {
        params.cartesianId = this.measurementJson.id;
      }

      params.productId = this.productData.productInfo.productId;
      params.shopId = this.productData.productInfo.belongShopBean.id;
      params.count = this.byNowParams.itemCount;
      params.type = 'add';
      console.log('===postParams=====', params);
      this.postParams(params);
    },
    postParams: function (data) {
      var that = this;
      var customIndex = getApp().globalData.AddClientUrl("/change_shopping_car_item.html", data, 'post');
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log('---------------change_shopping_car_item-----------------');
          console.log(res.data);
          wx.hideLoading();

          if (that.bindway == 'cart') {
            that.setData({
              showCount: false
            });
          }

          if (data.productId == 0) {
            console.log('购物车里面的商品数量');
            that.setData({
              countGood: res.data.totalCarItemCount
            });
          } else {
            if (res.data.productId && res.data.productId != 0) {
              if (data.count == 0) {
                console.log('通过加入购物车来确定购物车里面的商品数量');
              } else {
                wx.showToast({
                  title: '加入购物车成功'
                });
              }

              if (!!res.data.totalCarItemCount || res.data.totalCarItemCount == 0) {
                that.setData({
                  countGood: res.data.totalCarItemCount
                });
              }
            } else {
              wx.showToast({
                title: res.data.errMsg,
                image: '/wxcomponents/images/icons/tip.png',
                duration: 2000
              });
            }
          }
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },

    /**
     * 生命周期函数--监听页面加载
     */
    getPintuanData: function (productId, promotionId) {
      let that = this;
      let data = {
        status: 1,
        productId: productId,
        promotionId: promotionId
      };
      that.setData({
        pintuanParam: data
      });
      var pintuanUrl = getApp().globalData.AddClientUrl("/wx_find_pintuan_records.html", data, 'post');
      wx.request({
        url: pintuanUrl.url,
        data: pintuanUrl.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log('--------add----------');
          console.log(res.data);
          that.setData({
            pintuanListData: res.data.relateObj.result
          });

          if (that.pintuanListData.length == 1) {
            that.setData({
              visiblePintuanNum: 1
            });
          } else {
            that.setData({
              visiblePintuanNum: 2
            });
          }
        },
        fail: function (res) {
          getApp().globalData.loadFail();
        },
        complete: function () {
          wx.hideLoading();
        }
      });
    },
    getData: function (options, type) {
      let param = {};
      let that = this;

      if (!options) {
        param = that.dataFOr_getData;
      } else {
        param = options;
      }
      getApp().globalData.showToastLoading('loading', true);
      console.log('==param===', param); // let postParam = {}

      param.bagId = param.id || param.productId;
      // param.addShopId = param.addShopId||236;
      let customIndex = getApp().globalData.AddClientUrl("/wx_get_week_subscribe_bag.html", param);
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log(res);

          if (res.data.errcode == -1) {
            wx.showToast({
              title: res.data.errMsg,
              image: '/wxcomponents/images/icons/tip.png',
              duration: 1000
            });
            return;
          }else{
              let weekBag=res.data.relateObj
              for(let i=0;i<that.packageList.length;i++){
                 if(weekBag[that.packageList[i].paramName]){
                   that.packageList.splice(i,1,JSON.parse(weekBag[that.packageList[i].paramName]))
                 }
               }
               for(let i=0;i<that.packageList.length;i++){
                   for(let j=0;j<that.packageList[i].products.length;j++){
                       that.packageList[i].products[j].allReplaceStore=[]
                       console.log("that.packageList[i].products",that.packageList[i].products);
                       if(that.packageList[i].products[j].replaceStore&&that.packageList[i].products[j].replaceStore.length!=0){
                           let product={productId:that.packageList[i].products[j].productId,name:that.packageList[i].products[j].name,price:that.packageList[i].products[j].price,icon:that.packageList[i].products[j].icon}
                           let replaceStore=JSON.parse(JSON.stringify(that.packageList[i].products[j].replaceStore))
                           replaceStore.push(product)
                           console.log("===replaceStore====",replaceStore)
                           that.$set(that.packageList[i].products[j],'allReplaceStore',replaceStore)
                           that.replaceStoreData=replaceStore
                           console.log("====that.replaceStoreData===",that.replaceStoreData)
                       }
                       // if(j!=0){
                       //     console.log("that.packageList[i].products[j]",that.packageList[i].products[j])
                       //     that.packageList[i].replaceStore.push(that.packageList[i].products[j])
                       //     that.$set(that.packageList[i],'allData',that.packageList[i].replaceStore)
                       // }
                   }
               }
          }
          console.log("==that.packageList===",that.packageList)
          that.setData({
            pintuanState: false,
            weekPrice:(res.data.relateObj.price*7).toFixed(2),
            allPrice:((res.data.relateObj.price*7)*that.allCount).toFixed(2),
          });
          console.log('--------------getData-------------');
          let bannerData={jsonData:{autoplay:'autoplay',styleType:'product',width:690,height:348,images:[res.data.relateObj.banner]}}
          that.setData({
            productData: res.data.relateObj,
            bannerData:bannerData
          });

          if (res.data.images) {
            that.setData({
              totalImg: 1
            });
          }

          if (res.data.relateObj.description) {
			let articleJsonData=res.data.relateObj.description;
			that.setData({
			  articleJsonData: {jsonData:{content:articleJsonData}}
			});
            console.log('====articleJsonData====', that.articleJsonData);
          }

          console.log('productData', that.productData);
        },
        fail: function (res) {
          console.log("====fail=====");
          getApp().globalData.loadFail();

          if (!type) {
            console.log("======加载失败一次======");
            that.optionsData.someOneParam = 1;
            that.getData(that.optionsData, 'lastOne');
          }
        },
        complete: function (res) {
          wx.hideLoading();
        }
      });
    },
    getCart: function () {
      var params = {};
      params.productId = 0;
      params.count = 0;
      params.type = 'add';
      this.postParams(params);
    },
    closeGuigeZhezhao: function () {
      this.setData({
        showGuigeType: false
      });
      this.MeasureParams = [];
    },
    // 获取二维码
    getQrCode: function () {
      let userId = "";

      if (getApp().globalData.loginUser && getApp().globalData.loginUser.platformUser) {
        userId = getApp().globalData.loginUser.platformUser.id;
      } // console.log("app.loginUser.platformUser", app.loginUser.platformUser.id)
      // path=pageTab%2findex%2findex%3fAPPLY_SERVER_CHANNEL_CODE%3d'
      let postParam = {};
      postParam.SHARE_PRODUCT_DETAIL_PAGE = this.proId;
      postParam.scene = userId; // 上面是需要的参数下面的url

      console.log('====pp======', "/super_shop_manager_get_mini_code.html?mini=1&path=pageTab%2findex%2findex%3fSHARE_PRODUCT_DETAIL_PAGE%3d" + this.proId + "%26scene%3d" + userId);
      var customIndex = getApp().globalData.AddClientUrl("/super_shop_manager_get_mini_code.html?mini=1&path=pageTab%2findex%2findex%3fSHARE_PRODUCT_DETAIL_PAGE%3d" + this.proId + "%26scene%3d" + userId, postParam, 'get', '1');
      var result = customIndex.url.split("?");
      customIndex.url = result[0] + "?" + result[1];
      console.log("customIndex", customIndex.url, result[0]);
      var that = this;
      that.setData({
        qrCodeUrl: customIndex.url
      });
    },
    // 定位
    clickCatch: function (e) {
      console.log(this.productData.productInfo);
      let latitude = this.productData.productInfo.latitude;
      let longitude = this.productData.productInfo.longitude;
      let name = this.productData.productInfo.name;
      let address = this.productData.productInfo.location;
      wx.openLocation({
        latitude: latitude,
        longitude: longitude,
        scale: 12,
        name: name,
        address: address
      });
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>